home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13228 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  4.3 KB

  1. Path: news.internex.net.au!usenet
  2. From: sultan@connexus.apana.org.au (Jon Hornstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help with a very weird C problem
  5. Date: Sat, 06 Apr 1996 04:38:44 GMT
  6. Organization: connexus.apana.org.au
  7. Message-ID: <4k2tdl$ft4@preeda.internex.net.au>
  8. References: <31620c87.184254741@199.171.83.2>
  9. NNTP-Posting-Host: dialin-16.internex.net.au
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. With the briefest of looks at the code this function 
  13.  
  14.  
  15. >char *PkunzipDir(char *curdir,char *name2,char *file)
  16. >{
  17. >char pkunzip2[120] = "pkunzip ";
  18. >strcat(pkunzip2,curdir);
  19. >strcat(pkunzip2,name2);
  20. >strcat(pkunzip2," ");
  21. >strcat(pkunzip2,curdir);
  22. >strcat(pkunzip2,file);
  23. >return(pkunzip2);
  24. >}
  25.  
  26. should read
  27.  
  28.  
  29. char *PkunzipDir(char *curdir,char *name2,char *file)
  30. {
  31. static char pkunzip2[120] = "pkunzip ";
  32.  
  33.     strcat(pkunzip2,curdir);
  34.     strcat(pkunzip2,name2);
  35.     strcat(pkunzip2," ");
  36.     strcat(pkunzip2,curdir);
  37.     strcat(pkunzip2,file);
  38.     return(pkunzip2);
  39. }
  40.  
  41.  
  42. marty1@rbdc.rbdc.com (Jumping Jack Flash) wrote:
  43.  
  44. >Ok here's the problem. This program works great. BUT when I'm in the
  45. >c:\windows\desktop\programs directory instead of running the pkunzip
  46. >program it just shells a command.com, then after I type exit it
  47. >displays the ending screen. Here's the code
  48.  
  49. >#include <stdlib.h>
  50. >#include <conio.h>
  51. >#include <iostream.h>
  52. >#include <string.h>
  53. >#include <dir.h>
  54. >#include <process.h>
  55. >#include <stdio.h>
  56. >#include <errno.h>
  57. >#define TRUE 1
  58. >#define FALSE 0
  59.  
  60. >char *PkunzipDir(char *curdir,char *name2,char *file);
  61. >char *Current_Directory(char *path);
  62.  
  63. >int main(int argc, char **argv)
  64. >{
  65. >clrscr();
  66. >char drive[MAXDRIVE];
  67. >char dir[MAXDIR];
  68. >char file[MAXFILE];
  69. >char ext[MAXEXT];
  70. >char curdir[MAXPATH];
  71. >char *pkunzip_search;
  72. >struct ffblk ffblk;
  73. >int done, stat;
  74.  
  75. >//Searches all current dos paths for pkunzip
  76. >pkunzip_search = searchpath("pkunzip.exe");
  77. >if(pkunzip_search == NULL)
  78. >    {
  79. >    clrscr();
  80. >    cout << "PKUNZIP.EXE must be in your dos path!";
  81. >    exit(EXIT_FAILURE);
  82. >    }
  83.  
  84. >//Gets Current Directory & searches for first .zip file
  85. >Current_Directory(curdir);
  86.  
  87. >if(argc == 2)
  88. >    {
  89. >    done = findfirst(argv[1],&ffblk,0);
  90. >    if(done)
  91. >        {
  92. >         clrscr();
  93. >         cout << "No Zipped files in current Directory\n";
  94. >        }
  95. >    else
  96. >        {
  97. >        while (!done)
  98. >            {
  99. >            fnsplit(ffblk.ff_name,drive,dir,file,ext);
  100. >            stat = mkdir(file);
  101. >            if (!stat)
  102. >                {
  103. >                cout << "\n" << "Directory " << file
  104. ><< " created\n";
  105. >                cout << "Unzipping Files into it\n";
  106.  
  107. >system(PkunzipDir(curdir,ffblk.ff_name,file));
  108. >                }
  109.  
  110. >            else
  111. >                {
  112. >                clrscr();
  113. >                cout << "Unable to create directory "
  114. ><< file << "\n";
  115. >                cout << "For zipped file " << file <<
  116. >ext;
  117. >                }
  118. >            done = findnext(&ffblk);
  119. >            }
  120. >        }
  121. >    }
  122. >  else//A1
  123. >    {
  124. >    done = findfirst("*.zip",&ffblk,0);
  125. >    if(done)
  126. >        {
  127. >         clrscr();
  128. >         cout << "No Zipped files in current Directory\n";
  129. >        }
  130. >    else//A2
  131. >        {
  132. >        while (!done)
  133. >            {
  134. >            fnsplit(ffblk.ff_name,drive,dir,file,ext);
  135. >            stat = mkdir(file);
  136. >            if (!stat)
  137. >                {
  138. >                cout << "\n" << "Directory " << file
  139. ><< " created\n";
  140. >                cout << "Unzipping Files into it\n";
  141.  
  142. >system(PkunzipDir(curdir,ffblk.ff_name,file));
  143. >                }
  144. >            else
  145. >                {
  146. >                clrscr();
  147. >                cout << "Unable to create directory "
  148. ><< file << "\n";
  149. >                cout << "For zipped file " << file <<
  150. >ext;
  151. >                }
  152. >            done = findnext(&ffblk);
  153. >            }//Ends While
  154. >        }//Ends Else A2
  155. >    }//End Else A1
  156. >cout <<"\n" << "This program is Freeware\n";
  157. >cout << "Written by Marty A. Lineberry\n";
  158. >cout << "Internet address marty1@rbdc.rbdc.com\n";
  159. >cout << "End of Program\n";
  160. >return 0;
  161. >}
  162.  
  163.  
  164.  
  165. >char *PkunzipDir(char *curdir,char *name2,char *file)
  166. >{
  167. >char pkunzip2[120] = "pkunzip ";
  168. >strcat(pkunzip2,curdir);
  169. >strcat(pkunzip2,name2);
  170. >strcat(pkunzip2," ");
  171. >strcat(pkunzip2,curdir);
  172. >strcat(pkunzip2,file);
  173. >return(pkunzip2);
  174. >}
  175.  
  176. >//**********************************************************
  177. >//* Used to get the current Drive & Directory              *
  178. >//**********************************************************
  179. >char *Current_Directory(char *path)
  180. >{
  181. >   strcpy(path, "X:\\");      /* fill string with form of response:
  182. >X:\ */
  183. >   path[0] = 'A' + getdisk();    /* replace X with current drive
  184. >letter */
  185. >   getcurdir(0, path+3);  /* fill rest of string with current
  186. >directory */
  187. >   if(strlen(path) > 3) /* Puts ending / if not root directory */
  188. >    {
  189. >    strcat(path,"\\");
  190. >    }
  191. >   return(path);
  192. >}
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.